import 'package:bruno/bruno.dart';
import 'package:common/common.dart';
import 'package:common/image/image_tools.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../../theme/font.dart';
import '../report/report_view.dart';
import 'world_item_picture_widget.dart';

List<String> images = [
  'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimage109.360doc.com%2FDownloadImg%2F2017%2F09%2F0611%2F110221876_31_2017090611234561&refer=http%3A%2F%2Fimage109.360doc.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1739877385&t=f6f499fed41e9669a9ac6e76b604aa0a',
  'https://img.zcool.cn/community/01fd6e5821a7c1a84a0e282ba9dbf4.gif',
  'https://img0.baidu.com/it/u=1036855488,2737864377&fm=253&fmt=auto&app=138&f=GIF?w=365&h=241',
  'https://img1.baidu.com/it/u=2458364448,1188255234&fm=253&fmt=auto&app=138&f=GIF?w=391&h=256',
  'https://img1.baidu.com/it/u=3476030554,1312976222&fm=253&fmt=auto&app=120&f=JPEG?w=750&h=500',
  'https://inews.gtimg.com/news_bt/O_qHdht-j-Pc6-oSPkO0Nh5d2-gPK6YTa-ruo4P1aDQ5MAA/1000',
  'https://inews.gtimg.com/om_bt/OZ4uJUzOr-RgpNiB_zg4x8Zi1PYW02_D9hQeOhKhyq0GAAA/641',
  'https://inews.gtimg.com/om_bt/O6SG7dHjdG0kWNyWz6WPo2_3v6A6eAC9ThTazwlKPO1qMAA/641',
  'https://img1.baidu.com/it/u=959337756,4186275445&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=889'
];

class WorldItemWidget extends StatelessWidget {
  const WorldItemWidget({super.key, required this.index});

  final int index;
  @override
  Widget build(BuildContext context) {
    List imageList = images.sublist(0, index);
    String content =
        '今天心情很好哦今天心情很好哦今天心情很好哦今天心情很好哦今天心情很好哦今天心情很好哦今天心情很好哦今天心情很好今天心情很好哦今天还不错哦哈很好哦今天心情很好哦今天心情很好哦今天心情很好今天心情很好哦今天还不错哦哈很好哦今天心情很好哦今';
    bool isSystem = index == 0;
    bool isAudio = false;
    if (index == 9) {
      isAudio = true;
      imageList = [];
      content = '';
    }
    GlobalKey leftKey = GlobalKey();
    return Container(
        padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
        // margin: const EdgeInsets.symmetric(horizontal: 12),
        decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(8.r)), color: Colors.white),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                ImageView(
                    url: 'https://img.zcool.cn/community/01fd6e5821a7c1a84a0e282ba9dbf4.gif',
                    width: 37.w,
                    height: 37.w,
                    fit: BoxFit.cover,
                    type: ImageViewType.avater,
                    shape: BoxShape.circle),
                Expanded(
                  child: Container(
                    margin: const EdgeInsets.only(left: 10),
                    child: isSystem
                        ? Row(
                            children: [
                              Text('官方小喵',
                                  style: TextStyle(
                                      color: const Color(0xFF333333),
                                      fontSize: 16.sp,
                                      fontWeight: AppFontWeight.medium)),
                              const SizedBox(width: 5),
                              Image.asset('assets/app/images/world/world_guagfang_icon.png', height: 16.h)
                            ],
                          )
                        : Padding(
                            padding: const EdgeInsets.only(top: 10),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Row(
                                  children: [
                                    Text('喵喵小姐',
                                        style: TextStyle(
                                            color: const Color(0xFF333333),
                                            fontSize: 16.sp,
                                            fontWeight: AppFontWeight.medium)),
                                    const SizedBox(width: 5),
                                    Image.asset('assets/app/images/world/user_vip_icon.png', height: 16.h)
                                  ],
                                ),
                                const SizedBox(height: 5),
                                Text.rich(TextSpan(
                                    style: TextStyle(fontSize: 12.sp, color: const Color(0xFFF74437)),
                                    children: [
                                      WidgetSpan(
                                          alignment: PlaceholderAlignment.middle,
                                          child: Padding(
                                            padding: const EdgeInsets.only(right: 10),
                                            child:
                                                Image.asset('assets/app/images/world/user_sex_girl.png', height: 18.h),
                                          )),
                                      const TextSpan(text: '27岁'),
                                      const TextSpan(text: '射手座 · 河北张家口'),
                                    ])),
                              ],
                            ),
                          ),
                  ),
                ),
                if (!isSystem) _buildMoreButtonWarpper(context, leftKey),
              ],
            ),
            if (content.isNotEmpty)
              Container(
                padding: const EdgeInsets.symmetric(vertical: 10),
                child: BrnExpandableText(
                  text: content,
                  textStyle: TextStyle(color: const Color(0xFF000000), fontSize: 14.sp, height: 1.5),
                  moreTextStyle: TextStyle(color: const Color(0xFF25D4D0), fontSize: 14.sp, height: 1.5),
                  maxLines: 3,
                ),
              ),
            if (isAudio) _buildAudioWarpper(),
            if (imageList.isNotEmpty)
              WorldItemPictureWidget(
                // lRSpace: (12 * 2 + 16 * 2),
                lRSpace: (16 * 2),
                imageList: imageList,
                ignore: false,
              ),
            Container(
              alignment: Alignment.bottomCenter,
              padding: EdgeInsets.symmetric(vertical: 8.h),
              // height: 40,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text('刚刚 IP：河北', style: TextStyle(color: const Color(0xFF999999), fontSize: 12.sp)),
                  isSystem
                      ? Center(
                          child: BrnSmallMainButton(
                            title: "点击查看",
                            bgColor: const Color(0xFF25D4D0),
                            themeData: BrnButtonConfig(
                                smallButtonHeight: 26.h, smallButtonFontSize: 13, smallButtonRadius: 13.r),
                            insertPadding: const EdgeInsets.symmetric(horizontal: 8, vertical: 5),
                            onTap: () {},
                          ),
                        )
                      : Row(
                          children: [
                            Image.asset('assets/app/images/world/world_comment.png', width: 18.w),
                            const SizedBox(width: 30),
                            Row(
                              children: [
                                Image.asset('assets/app/images/world/world_zan_n.png', width: 18.w),
                                const SizedBox(width: 10),
                                Text('123', style: TextStyle(color: const Color(0xFF333333), fontSize: 13.sp)),
                              ],
                            ),
                          ],
                        )
                ],
              ),
            )
          ],
        ));
  }

  GestureDetector _buildMoreButtonWarpper(BuildContext context, GlobalKey<State<StatefulWidget>> leftKey) {
    return GestureDetector(
        onTap: () {
          BrnPopupWindow.showPopWindow(
            context,
            "提示内容",
            leftKey,
            spaceMargin: -5,
            backgroundColor: Colors.white,
            borderColor: Colors.white,
            borderWidth: 0,
            offset: 0,
            widget: SizedBox(
              height: 89,
              width: 88,
              child: Column(
                children: [
                  GestureDetector(
                    onTap: () {
                      Get.off(ReportPage());
                    },
                    child: Container(
                      height: 44,
                      alignment: Alignment.center,
                      child: Text('举报对方',
                          style: TextStyle(
                              color: const Color(0xFF333333), fontSize: 16.sp, fontWeight: AppFontWeight.medium)),
                    ),
                  ),
                  Container(
                    height: 1,
                    margin: const EdgeInsets.symmetric(horizontal: 10),
                    alignment: Alignment.center,
                    color: Colors.black.withOpacity(0.2),
                  ),
                  GestureDetector(
                    onTap: () {
                      Get.back();
                      SmartDialog.show(
                        usePenetrate: false,
                        clickMaskDismiss: true,
                        backType: SmartBackType.block,
                        keepSingle: true,
                        useAnimation: false,
                        builder: (context) => Center(
                          child: CustomAlertWidget(
                            title: '温馨提示',
                            content: "确认将对方加入黑名单吗？\n黑名单在“我的-系统设置“中。\n",
                            confirmText: '确定',
                            confirmAction: () {},
                            cancemText: '取消',
                          ),
                        ),
                      );
                    },
                    child: Container(
                      height: 44,
                      alignment: Alignment.center,
                      child: Text('拉黑对方',
                          style: TextStyle(
                              color: const Color(0xFF333333), fontSize: 16.sp, fontWeight: AppFontWeight.medium)),
                    ),
                  ),
                ],
              ),
            ),
            paddingInsets: const EdgeInsets.all(5),
          );
        },
        child: SizedBox(
            key: leftKey,
            height: 40,
            width: 40,
            child: Center(child: Image.asset('assets/app/images/world/world_more.png', height: 16.h))));
  }

  Container _buildAudioWarpper() {
    return Container(
        height: 38.h,
        width: 162.w,
        margin: EdgeInsets.only(top: 10.h),
        padding: EdgeInsets.symmetric(horizontal: 8.w),
        decoration:
            BoxDecoration(color: const Color(0xFF25D4D0), borderRadius: BorderRadius.all(Radius.circular(19.r))),
        child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
          Image.asset('assets/app/images/world/audio_play.png', width: 24.w),
          Image.asset('assets/app/images/world/audio_icon.png', height: 22.h),
          Text('27s', style: TextStyle(color: Colors.white, fontSize: 12.sp)),
        ]));
  }
}
